package com.haiya.visitor.basic;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ObjectStructure {
    private List<Element> list = new ArrayList<>();

    public void add(Element element) {
        list.add(element);
    }

    public void remove(Element element) {
        list.remove(element);
    }

    public void accept(Visitor visitor) {
        Iterator<Element> iterator = list.iterator();

        while(iterator.hasNext()) {
            Element next = iterator.next();
            ((Element) next).accept(visitor);
        }
    }
}
